package com.ruoyi.web.controller.bl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bl.domain.BlAd;
import com.ruoyi.bl.service.IBlAdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户广告Controller
 * 
 * @author ruoyi
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/bl/ad")
public class BlAdController extends BaseController
{
    @Autowired
    private IBlAdService blAdService;

    /**
     * 查询商户广告列表
     */
    @PreAuthorize("@ss.hasPermi('bl:ad:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlAd blAd)
    {
        startPage();
        List<BlAd> list = blAdService.selectBlAdList(blAd);
        return getDataTable(list);
    }

    /**
     * 导出商户广告列表
     */
    @PreAuthorize("@ss.hasPermi('bl:ad:export')")
    @Log(title = "商户广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlAd blAd)
    {
        List<BlAd> list = blAdService.selectBlAdList(blAd);
        ExcelUtil<BlAd> util = new ExcelUtil<BlAd>(BlAd.class);
        util.exportExcel(response, list, "商户广告数据");
    }

    /**
     * 获取商户广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('bl:ad:query')")
    @GetMapping(value = "/{adId}")
    public AjaxResult getInfo(@PathVariable("adId") Long adId)
    {
        return success(blAdService.selectBlAdByAdId(adId));
    }

    /**
     * 新增商户广告
     */
    @PreAuthorize("@ss.hasPermi('bl:ad:add')")
    @Log(title = "商户广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlAd blAd)
    {
        return toAjax(blAdService.insertBlAd(blAd));
    }

    /**
     * 修改商户广告
     */
    @PreAuthorize("@ss.hasPermi('bl:ad:edit')")
    @Log(title = "商户广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlAd blAd)
    {
        return toAjax(blAdService.updateBlAd(blAd));
    }

    /**
     * 删除商户广告
     */
    @PreAuthorize("@ss.hasPermi('bl:ad:remove')")
    @Log(title = "商户广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adIds}")
    public AjaxResult remove(@PathVariable Long[] adIds)
    {
        return toAjax(blAdService.deleteBlAdByAdIds(adIds));
    }
}
